import { createRouter, createWebHashHistory } from 'vue-router'
const router = createRouter({
  history: createWebHashHistory(), // 路由模式
  routes: [ // 路由规则
    {
      path: '/',
      name: 'login',
      component: () => import('../views/login/login.vue'),
      beforeEnter: (to, from) => {
        if (to.path === '/' && sessionStorage.getItem('userName')) {
          return '/index'
        } else {
          return true
        }
      }
    },
    {
      path: '/index',
      name: 'index',
      component: () => import('../views/search/index.vue'),
      beforeEnter: (to, from) => {
        if (!sessionStorage.getItem('userName')) {
          return '/'
        } else {
          return true
        }
      }
    }
  ]
})
export default router
